#include <dbus/dbus-glib.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    GError *error = NULL;
    DBusGConnection *conn;
    DBusGProxy *proxy;
    char *str = NULL;
    //connect to session bus(DBUS_BUS_SYSTEM for system bus)
    conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
    if(conn == NULL) {
        g_printerr("Failed to open connection to bus:%s\n", error->message);
        g_error_free(error);
        exit(1);
    }
    //create a proxy object
    proxy = dbus_g_proxy_new_for_name (
        conn, //connection 
        "org.freedesktop.Notifications", //service name
        "/", //instance path
        "org.freedesktop.DBus.Introspectable" //insterface
    );
    error = NULL;
    if(!dbus_g_proxy_call(
        proxy, //proxy
        "Introspect", //method
        &error, //for error
        G_TYPE_INVALID, //method input type/value pairs, end with G_TYPE_INVALID
        G_TYPE_STRING, &str, G_TYPE_INVALID
                  //method output type/value pairs, end with G_TYPE_INVALID
    )){
        if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
            g_printerr("Caught remote method exception:%s-%s\n", dbus_g_error_get_name(error), error->message);
        }else {
            g_printerr("Error:%s\n", error->message);
        }   
        g_error_free(error);
        exit(1);
    }   
    g_print("Message of method return from bus:\n%s\n", str);
    g_free(str);
    g_object_unref(proxy); //will call exit ?
    exit(1);
    return 0;
}
